package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.MesSaleOrderDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:35:43
 */
@Repository
public class MesSaleOrderDetailDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(MesSaleOrderDetailDao.class);

    public MesSaleOrderDetail insert(final MesSaleOrderDetail mesSaleOrderDetail) {
        insert("MesSaleOrderDetail.insert", mesSaleOrderDetail);
        return mesSaleOrderDetail;
    }

    public Boolean updateInfoById(final MesSaleOrderDetail mesSaleOrderDetail) {
        return update("MesSaleOrderDetail.updateInfoById", mesSaleOrderDetail) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("MesSaleOrderDetail.updateInfoByQuery", query) > 0;
    }

    public MesSaleOrderDetail selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("MesSaleOrderDetail.selectById", query);
    }

    public List<MesSaleOrderDetail> selectByQuery(final Query query) {
        return queryForList("MesSaleOrderDetail.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("MesSaleOrderDetail.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        MesSaleOrderDetail mesSaleOrderDetail = new MesSaleOrderDetail();
        mesSaleOrderDetail.setDeleteFlag(1);
        mesSaleOrderDetail.setId(id);
        mesSaleOrderDetail.setEntId(entId);

        return update("MesSaleOrderDetail.updateInfoById", mesSaleOrderDetail) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("MesSaleOrderDetail.deleteById", query) > 0;
    }

    //获取某个商品的总生产数
    public Long getProductProduceCount(final Query query) {
        return queryForObject("MesSaleOrderDetail.selectProductProduceCount", query);
    }
}